<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <style>
        	*{
        		outline:none;
        	}
        </style>
    </head>
    <body>
		<div ng-app="myApp" >
			<div ng-controller="logCtr">
		  <div class="form-group" >
		  <h1 class="text-center">请用户登录</h1>
		    <label for="username">用户名</label>
		    <input type="text" class="form-control" ng-model="username" id="username" placeholder="username">
		  </div>
		  <div class="form-group">
		    <label for="password">密码</label>
		    <input type="password" class="form-control" ng-model="password" id="password" placeholder="password">
		  </div>
		  
		  <button class="btn btn-success" ng-click="login()">登录</button>
		  <button class="btn btn-primary pull-right" ng-click="sign()">注册</button>

			<section>
				
			
		  <div class="alert alert-danger alert-dismissible" ng-show="none" ng-cloak role="alert">
			  <button type="button" class="close"><span  ng-click="fornone()">&times;</span></button>
			  <strong>错误!</strong> 用户名或密码不正确
		  </div>
		  </section>
		  </div>
		</div>
	
	<script src='js/jquery-1.11.1.js'></script>
    <script src="js/angular.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
    		var app = angular.module('myApp',[]);
    		app.controller('logCtr',function($scope){
    			$scope.none = false;
    			$scope.login = function(){
    				let username = angular.element('#username').val();
    				let password = angular.element('#password').val();
    				let data = {
    					username:username,
    					password:password
    				}
    				$.post('http://localhost:3000/login',data,function(data,textStatus,xhr){
    					if(String(data)=="none"){
    						$scope.$apply(function(){
    							$scope.none = true;
    						})   						
    					}else{
    						localStorage.setItem("username", username);
    						window.location.href = "http://localhost:3000/goodsdetail";
    					}
    				})
    			}
    			$scope.sign = function(){
    				window.location.href = "http://localhost:3000/regpage";
    			}
    			$scope.fornone = function(){
    				$scope.none = false;
    				console.log($scope.none);
    				
    			}
    		})
    </script>
    </body>
</html>